package appapi.config;

import appapi.Global.MyJwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * JWT拦截配置
 *
 * @author luocheng
 * @version 1.0
 * @date 2023/05/20 16:09
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())
                //拦截所有请求，通过判断token来决定是否需要登陆
                .addPathPatterns("/**")
                //.excludePathPatterns("/**");
                .excludePathPatterns("/api/login/**","/external/testSign/**","/api/File/**","/webjars/**","/v3/api-docs",
                        "/swagger-resources/configuration/ui",
                        "/swagger-resources",
                        "/swagger-resources/configuration/security",
                        "/doc.html",
                        "/api/camer/**",
                        "/api/app/**",
                        "/api/File/**",
                        "/external/tokenApi/**",
                        "/external/device/**",
                        "/api/update/GetServerSoftLastVersion/**",
                        "/api/facerecord/addInfo",
                        "/device/data/realDataList",
                        "/device/data/add",
                        "/device/data/realAlarmDataList"
                        );
    }

    @Bean
    public MyJwtInterceptor jwtInterceptor() {
        return new MyJwtInterceptor();
    }
}
